package com.example.smartwaterapi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.smartwaterapi.entity.Watchface;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 表盘Mapper接口
 */
@Mapper
public interface WatchfaceMapper extends BaseMapper<Watchface> {
    
    /**
     * 增加下载次数
     */
    @Update("UPDATE watchfaces SET download_count = download_count + 1 WHERE id = #{id}")
    int incrementDownloadCount(@Param("id") Long id);
    
    /**
     * 获取热门表盘
     */
    @Select("SELECT * FROM watchfaces WHERE status = 1 " +
            "ORDER BY (download_count * 0.6 + rating_avg * rating_count * 0.4) DESC " +
            "LIMIT #{limit}")
    List<Watchface> getPopularWatchfaces(@Param("limit") Integer limit);
} 